<?php
// +----------------------------------------------------------------------
// | my
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: $this <498944516@qq.com>
// +----------------------------------------------------------------------
namespace app\rob\model;

use think\Model;

class RobApp extends Model
{

    protected $table = "my_rob_app";
    protected $insert = ['status'=>1];  
    protected $autoWriteTimestamp = true;

    /**
     * 获取机器人具有的APP处理能力
     */
    public function reply($keyword,$rob_apps,$data=[]){
    	
       
      
       $apps=$this->where('id','in',$rob_apps)->select();
       
       if ($apps){
    	      foreach ($apps as $key => $app) {
               if (strstr($keyword,$app->keyword)){
                $data['app']=$app;
                $data['keyword']=$app->keyword;
    		        $data['before'] = substr($keyword,0,strrpos($keyword,$app->keyword));
    		        $data['back']=str_replace($data['before'].$app->keyword,"",$keyword);
                $model_name=$app->model_name.'/WeApp';
               
                $reply=model($model_name)->index($data);
                
                return $reply;
    		       }  
            }
         }
         
    }

    public function editData(){

      $data=input("post.");
      $data['aid']=session('aid');
      if (isset($data['id'])){
         $res = $this->allowField(true)->where('id',$data['id'])->update($data);
      }else{
         $data['aid']=session('aid');
         $res = $this->allowField(true)->data($data)->save();
      }
      
      return $res;
    }



    
}